package cn.schoolwow.util.test.module.query.resource.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.resource.QueryResource;
import cn.schoolwow.util.domain.query.resource.QueryResourceResponse;
import cn.schoolwow.util.module.query.resource.domain.SingleQueryResourceHandler;
import org.junit.Assert;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class WalkChineseNameDirectoryResourceTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        AtomicInteger atomicInteger = new AtomicInteger(0);

        List<String> fileNameList = new ArrayList<>();
        QueryResource.newQuery("中文目录", "module/query/resource/中文目录")
                .fileNameEndWith(".json")
                .singleQueryResourceHandler(new SingleQueryResourceHandler() {
                    @Override
                    public boolean handleQueryResourceResponse(QueryResourceResponse queryResourceResponse) {
                        String fileName = queryResourceResponse.getFileName();
                        fileNameList.add(fileName);
                        atomicInteger.set(1);
                        return true;
                    }
                })
                .execute()
                .walkResource();
        if(atomicInteger.get()==0){
            throw new IllegalArgumentException("walkResource遍历资源为空");
        }
        Assert.assertTrue(fileNameList.contains("角色表.json"));
        Assert.assertTrue(fileNameList.contains("项目表.json"));
    }

    @Override
    public String name() {
        return "遍历中文文件夹测试用例";
    }
}
